﻿using Esri.ArcGISRuntime.Data;
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;

namespace classTest
{
    /// <summary>
    /// QueryResultWindow.xaml 的交互逻辑
    /// </summary>
    public partial class QueryResultWindow : Window
    {
        private FeatureQueryResult featureQuerySet; //查询结果集合
        public QueryResultWindow()
        {
            InitializeComponent();
        }

        public FeatureQueryResult FeatureQuerySet
        {
            get { return featureQuerySet; }
            set { featureQuerySet = value; }
        }

        // 对该查询结果子窗体的加载事件进行处理
        private void resultWindow_Loaded(object sender, RoutedEventArgs e)
        {
            if (featureQuerySet != null && featureQuerySet.Count()>0)//结果不为空
            {
                foreach(Feature f in featureQuerySet)
                {
                    ComboBoxItem cbi = new ComboBoxItem();
                    string name = "null";
                    for(int i =0;i< f.Attributes.Keys.Count; i++)
                    {
                        if (f.Attributes.Keys.ElementAt(i).ToLower() == "name")
                        {
                            name = f.Attributes.Values.ElementAt(i).ToString();
                            break;
                        }
                    }
                    cbi.Content = name;
                    comboBoxSelectionCount.Items.Add(cbi);
                }
                comboBoxSelectionCount.SelectedIndex = 0;
            }
        }

        // 为查询结果子窗体中的组合框选择事件添加代码
        private void comboBoxSelectionCount_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (featureQuerySet != null)//查询结果集不为空
            {
                int idx = comboBoxSelectionCount.SelectedIndex;//获得选择项的索引
                if (idx > -1)
                {
                    Feature ft = featureQuerySet.ElementAt(idx);//获取索引所在的要素对象

                    string introduction = "暂无介绍";
                    for (int i = 0; i < ft.Attributes.Keys.Count; i++)
                    {
                        if (ft.Attributes.Keys.ElementAt(i).ToLower() == "introduction")
                        {
                            introduction = ft.Attributes.Values.ElementAt(i).ToString();
                            break;
                        }
                    }
                    Random random = new Random();
                    var picPath = $"..\\..\\Image\\scauImage\\{random.Next(1, 39)}.jpg";
                    pointImage.Source = new BitmapImage(new Uri(picPath, UriKind.Relative));
                    Introduction.Text = introduction;
                }
            }
        }

        // 在主窗体类中添加一个新的成员变量，用来标记按照位置查询的类型


    }
}
